package com.sgb.kjwl.view.ui.activity.self.authentication;

import android.content.Context;
import android.content.Intent;

import androidx.databinding.DataBindingUtil;

import android.os.Bundle;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityCommitSuccessBinding;
import com.sgb.kjwl.model.entity.SuccessEntity;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.SuccessType;
import com.sgb.kjwl.view.event.self.AuthenticationEvent;
import com.sgb.kjwl.view.event.self.DevicePublishEvent;
import com.sgb.kjwl.view.event.self.MachinePublishEvent;
import com.sgb.kjwl.view.event.self.PackersPublishEvent;
import com.sgb.kjwl.view.ui.activity.device.DeviceDetailActivity;
import com.sgb.kjwl.view.ui.activity.leaseAsk.MachineOutActivity;
import com.sgb.kjwl.view.ui.activity.pick.EnterpriseBiddingActivity5;
import com.sgb.kjwl.view.ui.activity.pick.QuoteImmediatelyActivity;
import com.sgb.kjwl.view.ui.activity.self.pick.SelfQuoteImmediatelyActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.AddGoodsActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.DevicePublishActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.MachinePublishInActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.MachinePublishOutActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.PackersPublishActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.PackersPublishNextActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.PersonPublishNextActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.PersonnelPublishActivity;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.helper.AppManagerHelper;

import org.greenrobot.eventbus.EventBus;

public class CommitSuccessActivity extends AppActivity {
    private ActivityCommitSuccessBinding binding;
    private SuccessEntity dates;

    @Override
    protected boolean statusBarDark() {
        return false;
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    public static void start(Context context, SuccessEntity dates) {
        Intent intent = new Intent(context, CommitSuccessActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("dates", dates);
        intent.putExtras(bundle);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(CommitSuccessActivity.this, R.layout.activity_commit_success);
        //   binding.setViewModel(viewModel);
//        binding.include.actionBarTitle.setText(getResources().getString(R.string.self_supplier_auth));
        binding.include.actionBarImageLeft.setVisibility(View.VISIBLE);
        binding.include.actionBarImageLeft.setOnClickListener(this);
        binding.knowTv.setOnClickListener(this);
    }

    @Override
    protected void init() {
        dates = (SuccessEntity) getIntent().getSerializableExtra("dates");
        binding.titleTv.setText(dates.getTitle());
        binding.contentTv.setText(dates.getContent());
        binding.knowTv.setText(dates.getButtonText());
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.action_bar_image_left:
                complate();
                break;
            case R.id.know_tv:
                complate();
                break;
        }
    }

    private void complate() {
        AppManagerHelper.getAppManagerHelper().finishActivity(CommitSuccessActivity.class);
        if (dates.getType() == SuccessType.SUCC_PACK) {
            AppManagerHelper.getAppManagerHelper().finishActivity(PackersPublishNextActivity.class);
            AppManagerHelper.getAppManagerHelper().finishActivity(PackersPublishActivity.class);
            EventBus.getDefault().post(PackersPublishEvent.make().setMessageTag(EventConstant.EVENT_PUBLISH_LIST_REFUSH));
        } else if (dates.getType() == SuccessType.SUCC_PERSON) {
            AppManagerHelper.getAppManagerHelper().finishActivity(PersonPublishNextActivity.class);
            AppManagerHelper.getAppManagerHelper().finishActivity(PersonnelPublishActivity.class);
        } else if (dates.getType() == SuccessType.SUCC_DEVICE) {
            AppManagerHelper.getAppManagerHelper().finishActivity(DevicePublishActivity.class);
            AppManagerHelper.getAppManagerHelper().finishActivity(DeviceDetailActivity.class);
            EventBus.getDefault().post(DevicePublishEvent.make().setMessageTag(EventConstant.EVENT_PUBLISH_DEVICE_REFUSH));
        } else if (dates.getType() == SuccessType.SUCC_MACHINE_IN) {
            AppManagerHelper.getAppManagerHelper().finishActivity(MachinePublishInActivity.class);
            EventBus.getDefault().post(MachinePublishEvent.make().setMessageTag(EventConstant.EVENT_PUBLISH_MACHINE_REFUSH));
        } else if (dates.getType() == SuccessType.SUCC_MACHINE_OUT) {
            AppManagerHelper.getAppManagerHelper().finishActivity(MachinePublishOutActivity.class);
            AppManagerHelper.getAppManagerHelper().finishActivity(MachineOutActivity.class);
            EventBus.getDefault().post(MachinePublishEvent.make().setMessageTag(EventConstant.EVENT_PUBLISH_MACHINE_REFUSH));
        } else if (dates.getType() == SuccessType.SUCC_GOODS) {
            EventBus.getDefault().post(EventConstant.EVENT_PUBLISH_GOODS_REFRESH);
            AppManagerHelper.getAppManagerHelper().finishActivity(AddGoodsActivity.class);
        } else if (dates.getType() == SuccessType.ENTERPRISE_BIDDING) {
            AppManagerHelper.getAppManagerHelper().finishActivity(EnterpriseBiddingActivity5.class);
            EventBus.getDefault().post(MachinePublishEvent.make().setMessageTag(EventConstant.EVENT_ENTERPRISE_BIDDING_COMMIT));
        } else if (dates.getType() == SuccessType.PICK_OFFER) {
            EventBus.getDefault().post(MachinePublishEvent.make().setMessageTag(dates.getId()));
            AppManagerHelper.getAppManagerHelper().finishActivity(QuoteImmediatelyActivity.class);
        } else if (dates.getType() == SuccessType.BUSINESS_OFFER) {
            EventBus.getDefault().post(MachinePublishEvent.make().setMessageTag(dates.getId()));
            AppManagerHelper.getAppManagerHelper().finishActivity(SelfQuoteImmediatelyActivity.class);
        } else if (dates.getType() == SuccessType.TEAM_AUTH) {
            EventBus.getDefault().postSticky(AuthenticationEvent.make(EventConstant.EVENT_JOIN_COM, 0));
            AppManagerHelper.getAppManagerHelper().finishActivity(TeamAuthActivity.class);
        }
    }
}
